package com.xxtx.trade.config;

import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.validation.constraints.Pattern;

/**
 * 微信支付相关配置
 */
@Configuration
@EnableConfigurationProperties(WxPayProperties.class)
public class WxPayConfiguration {
	@Value("${pay.appId}")
	private String appId;

	@Value("${pay.mchId}")
	private String mchId;

	@Value("${pay.keySign}")
	private String keySign;

	@Value("${pay.appSecret}")
	private String appSecret;

	@Value("${pay.notify}")
	private String notify;

	@Value("${pay.p12Path}")
	private String p12Path;

	@Autowired
	private WxPayProperties wxPayProperties;

	@Bean
	public WxPayConfig payConfig() {
		WxPayConfig payConfig = new WxPayConfig();
		payConfig.setAppId(appId);
		payConfig.setMchId(mchId);
		payConfig.setMchKey(keySign);
//		payConfig.setSubAppId(this.subAppId);
//		payConfig.setSubMchId(this.subMchId);
		payConfig.setNotifyUrl(notify);
		payConfig.setKeyPath(p12Path);
		return payConfig;
	}


	@Bean
	public WxPayService payService() {
		WxPayService payService = new WxPayServiceImpl();
		payService.setConfig(payConfig());
		return payService;
	}


}
